package com.hz.basic.service.impl;

import com.hz.basic.entity.*;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hz.common.utils.PageUtils;
import com.hz.common.utils.Query;

import com.hz.basic.dao.CbStiffTypefaceDao;
import com.hz.basic.service.CbStiffTypefaceService;


@Service("cbStiffTypefaceService")
public class CbStiffTypefaceServiceImpl extends ServiceImpl<CbStiffTypefaceDao, CbStiffTypefaceEntity> implements CbStiffTypefaceService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<CbStiffTypefaceEntity> page = this.page(
                new Query<CbStiffTypefaceEntity>().getPage(params),
                new QueryWrapper<CbStiffTypefaceEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public CbStiffChalkVideoEntity getchalkvideobytid(Long tid){
        CbStiffTypefaceDao baseMapper = this.baseMapper;
        return baseMapper.getchalkvideobytid(tid);
    }

    @Override
    public CbStiffPenVideoEntity getpenvideobytid(Long tid){
        CbStiffTypefaceDao baseMapper = this.baseMapper;
        return baseMapper.getpenvideobytid(tid);
    }

    @Override
    public CbStiffLiteracyVideoEntity getliteracyvideobytid(Long tid){
        CbStiffTypefaceDao baseMapper = this.baseMapper;
        return baseMapper.getliteracyvideobytid(tid);
    }

    @Override
    public PageUtils<List<CbStiffTypefaceEntity>> getstifftypefacesbycondition(String content, int curpage, int numpage) {
        int total = this.baseMapper.getstifftypefacestotal(content);
        //不合理的curpage，越界
        if(curpage <= 0 || Math.ceil((double)total/numpage) < curpage)
            return new PageUtils(new ArrayList<CbStiffTypefaceEntity>(),total,numpage,curpage);
        List<CbStiffTypefaceEntity> expandResources = this.baseMapper.getstifftypefacesbycondition(content, (curpage-1)*numpage,numpage);
        PageUtils<List<CbStiffTypefaceEntity>> page = new PageUtils(expandResources,total,numpage,curpage);
        return page;
    }
}







